* Gary LaMotte's Mathematica solutions to exercises from the 2012 Gravitational Wave Astronomy Summer School

*DAY 5  PART2.*

*a.*

samprate=16384;

dataA =  Flatten[Import["C:\\Users\\Gary LaMotte\\Documents\\Shawhan GW Lectures and Exercises\\day5dataA.txt", "Table"]];

dataB =  Flatten[Import["C:\\Users\\Gary LaMotte\\Documents\\Shawhan GW Lectures and Exercises\\day5dataB.txt", "Table"]];

tdataA =  Table[(r-1.0)/samprate  , {r,Length[dataA]}];tdataB =  Table[(r-1.0)/samprate  , {r,Length[dataB]}];
ndataA = Length[dataA];dataAsecs = ndataA/samprate;  ndataB = Length[dataB];dataBsecs = ndataB/samprate;

*b. and  c.*

*Define a Cross Correlation Function:*

crosscorrelation[stepincrement_,winsize_]:=
(stepbins = Floor[stepincrement*samprate];
winbins = Floor[winsize*samprate];
dataAsegs = Table[dataA[[i;;winbins+i]],{i,1,Length[dataA]-winbins,stepbins}];
dataBsegs = Table[dataB[[i;;winbins+i]],{i,1,Length[dataB]-winbins,stepbins}];
corr=Flatten[Table[{dataAsegs[[j]].dataBsegs[[j]]},{j,1,Length[dataAsegs]}]];
tcorr =  Table[(r-1.0)*stepbins/samprate  , {r,Length[corr]}];
correlationseries = Transpose[{tcorr, corr}];
ListLinePlot[correlationseries,PlotRange->{{0,16},{1.1*Min[corr],1.1*Max[corr]}}, Frame->True,FrameLabel->{Time,Amplitude}])

*Input Values for Graphing:*

stepincrement = 0.010;

winsize = 0.020;

crosscorrelation[stepincrement,winsize]

*d.*

winsize = 0.100;

crosscorrelation[stepincrement,winsize]

winsize = 0.500;

crosscorrelation[stepincrement,winsize]

*e.*

*FOR DATA A:  Apply Square PassBand Filter Subprogram:*

Clear[lowcorn,upcorn, filtdataA]

filtdataA[lowcorn_,upcorn_]:=
(start = {1,1}; pass = PadRight[start, ((upcorn - lowcorn)*dataAsecs)+1, 1]; rtside = PadRight[pass, ndataA-((lowcorn*dataAsecs)-1),0]; sqfilt = PadLeft[rtside,ndataA];  
sinc = InverseFourier[sqfilt]; realsinc =  2*Re[sinc];ListConvolve[realsinc/Sqrt[Length[realsinc]],dataA,1])

lowcorn =  64;

upcorn = 2048;

filtdataA = filtdataA[lowcorn,upcorn];

*FOR DATA B:  Apply Square PassBand Filter Subprogram:*

Clear[lowcorn,upcorn, filtdataB]

filtdataB[lowcorn_,upcorn_]:=
(start = {1,1}; pass = PadRight[start, ((upcorn - lowcorn)*dataBsecs)+1, 1]; rtside = PadRight[pass, ndataB-((lowcorn*dataBsecs)-1),0]; sqfilt = PadLeft[rtside,ndataB];  
sinc = InverseFourier[sqfilt]; 
realsinc =  2*Re[sinc]; 
filtdataB = ListConvolve[realsinc/Sqrt[Length[realsinc]],dataB,1])

lowcorn =  64;

upcorn = 2048;

filtdataB = filtdataB[lowcorn,upcorn];

*Define a Cross Correlation Function for Filtered Data:*

filtcrosscorrelation[stepincrement_,winsize_]:=
(stepbins = Floor[stepincrement*samprate];
winbins = Floor[winsize*samprate];
filtdataAsegs = Table[filtdataA[[i;;winbins+i]],{i,1,Length[filtdataA]-winbins,stepbins}];
filtdataBsegs = Table[filtdataB[[i;;winbins+i]],{i,1,Length[filtdataB]-winbins,stepbins}];
corr=Flatten[Table[{filtdataAsegs[[j]].filtdataBsegs[[j]]},{j,1,Length[filtdataAsegs]}]];
tcorr =  Table[(r-1.0)*stepbins/samprate  , {r,Length[corr]}];
filtcorrelationseries = Transpose[{tcorr, corr}];
ListLinePlot[filtcorrelationseries,PlotRange->{{0,16},{1.1*Min[corr],1.1*Max[corr]}}, Frame->True,FrameLabel->{Time,Amplitude}])

*Input Values to obtain Cross Correlation:*

stepincrement = 0.010;

winsize = 0.020;

filtcrosscorrelation[stepincrement,winsize]

winsize = 0.100;

filtcrosscorrelation[stepincrement,winsize]

winsize = 0.500;

filtcrosscorrelation[stepincrement,winsize]